// PSPIDQuery.cpp: implementation of the PSPIDQuery class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "PSPIDQuery.h"
#include "PHSRecentWork.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

PSPIDQuery::PSPIDQuery()
{

}
		
PSPIDQuery::~PSPIDQuery()
{

}

PSPIDQuery::Iterator * PSPIDQuery::GetSameIDParts(const CString &strPartID)
{
	ASSERT(!strPartID.IsEmpty());
	ASSERT(this->Get(strPartID));

	return this->Get(strPartID);
}

void PSPIDQuery::RemoveSortProperty(PartSortProperty *pProperty)
{
	ASSERT(pProperty);
	this->RemoveKey(pProperty->ID());
}

void PSPIDQuery::AddSortProperty(PartSortProperty * pProperty)
{
	ASSERT(pProperty);
	this->Add(pProperty->ID(),pProperty);
}

PartSortProperty* PSPIDQuery::GetCurPSPByID(const CString& strPartID)
{		
	Iterator * pSameKeyIter = GetSameIDParts(strPartID);
	
	for(pSameKeyIter->Begin(); !pSameKeyIter->End(); pSameKeyIter->Next()) 
	{
		PartSortProperty *pProperty = pSameKeyIter->Get();
		if( IsCurStandard(pProperty->Standard()))
		{
			delete pSameKeyIter;
			return pProperty;
		}
	}
	delete pSameKeyIter;
	ASSERT(FALSE);

	return NULL;
}


BOOL PSPIDQuery::IsCurStandard(const CString& strStandard)
{
	if (GetRecentWork().PAStandard() == strStandard || 
		GetRecentWork().SAStandard() == strStandard ||
		GetRecentWork().ConnectStandard() == strStandard ||
		GetRecentWork().SpringStandard() == strStandard ||
		GetRecentWork().ConstSpringStandard() == strStandard ||
		GetRecentWork().BoltNutStandard() == strStandard ||
		GetRecentWork().AttachStandard() == strStandard ||
		GetRecentWork().ProfiledBarStandard() == strStandard)
		return TRUE;

	return FALSE;
}
